const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const Users = sequelize.define('Users', {
  id: {
    type: DataTypes.BIGINT,
    allowNull: false,
    autoIncrement: true,
    comment: '用户ID',
  },
  username: {
    type: DataTypes.STRING(50),
    allowNull: false,
    comment: '用户名',
  },
  email: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: '邮箱',
  },
  passwordHash: {
    type: DataTypes.STRING(255),
    allowNull: false,
    comment: '密码哈希',
  },
  phone: {
    type: DataTypes.STRING(20),
    comment: '手机号',
  },
  avatar: {
    type: DataTypes.STRING(255),
    comment: '头像URL',
  },
  role: {
    type: DataTypes.ENUM,
    defaultValue: user,
    comment: '用户角色',
  },
  status: {
    type: DataTypes.ENUM,
    defaultValue: active,
    comment: '账户状态',
  },
  apiKey: {
    type: DataTypes.STRING(255),
    comment: 'OKX API Key',
  },
  apiSecret: {
    type: DataTypes.STRING(255),
    comment: 'OKX API Secret',
  },
  passphrase: {
    type: DataTypes.STRING(255),
    comment: 'OKX API Passphrase',
  },
  lastLoginAt: {
    type: DataTypes.DATE,
    comment: '最后登录时间',
  },
  deletedAt: {
    type: DataTypes.DATE,
    comment: '删除时间',
  },
  createdAt: {
    type: DataTypes.DATE,
    defaultValue: CURRENT_TIMESTAMP,
    comment: '创建时间',
  },
  updatedAt: {
    type: DataTypes.DATE,
    defaultValue: CURRENT_TIMESTAMP,
    comment: '更新时间',
  },
  createdBy: {
    type: DataTypes.BIGINT,
    comment: '创建人',
  },
  updatedBy: {
    type: DataTypes.BIGINT,
    comment: '修改人',
  }
}, {
  tableName: 'users',
  comment: '用户表',
  timestamps: true,
  paranoid: true,
  underscored: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at',
  deletedAt: 'deleted_at'
});

module.exports = Users;
